<template>
  <div
    style="margin-top: 15px;min-height: 100%;"
    class="main-div"
  >
    <Spin v-show="isSpinShow" fix size="large" />

    <Card>
      <div slot="title">

        <div v-if="multiInstanceTaskBtns && multiInstanceTaskBtns.length>0">
          <Button v-for="item in taskSequence" type="primary" style="margin-bottom: 2px;margin-right: 15px;" @click="action(item,item.alias)">{{ item.name }}</Button>

          <span v-for="item in multiInstanceTaskBtns">

            <Button class="ivu-btn ivu-btn-success" style="margin-bottom: 2px;margin-right: 15px;" @click="action(item)">{{ item.btnName }}</Button>
          </span>

        </div>

        <div v-if="taskBtns.length>0">
          <Button v-for="item in taskSequence" type="primary" style="margin-bottom: 2px;margin-right: 15px;" @click="action(item,'sequence')">{{ item.name }}</Button>

          <span v-for="item in taskBtns">

            <Button class="ivu-btn ivu-btn-success" style="margin-bottom: 2px;margin-right: 15px;" @click="action(item)">{{ item.btnName }}</Button>
          </span>
          <span>
            <Button type="primary" style="margin-bottom: 2px;margin-right: 15px;" @click="go">
              <Icon type="md-close" />关闭
            </Button>

          </span>

        </div>

        <span v-else>
        <Button v-for="item in taskSequence" type="primary" style="margin-bottom: 2px;margin-right: 15px;" @click="action(item,'sequence')">{{ item.name }}</Button>

          <Button
            class="ivu-btn ivu-btn-success"
            style="margin-bottom: 2px;margin-right: 15px;"
            @click="action('agree')"
          >

            <Icon type="md-checkmark" /> 办理</Button>

          <Button type="primary" style="margin-bottom: 2px;margin-right: 15px;" @click="action('informed')">传阅
          </Button>

          <Button
            type="primary"
            style="margin-bottom: 2px;margin-right: 15px;"
            @click="action('transferTask')"
          >转办
          </Button>
          <Button
            type="primary"
            style="margin-bottom: 2px;margin-right: 15px;"
            @click="action('transactionUrge')"
          >特事特办
          </Button>
          <Button
            type="primary"
            style="margin-bottom: 2px;margin-right: 15px;"
            @click="action('backToNode')"
          >退回
          </Button>
          <Button type="error" style="margin-bottom: 2px;margin-right: 15px;" @click="action('invalid')">作废
          </Button>
          <Button type="primary" style="margin-bottom: 2px;margin-right: 15px;" @click="action('saveDraft')">保存
          </Button>
          <Button type="primary" style="margin-bottom: 2px;margin-right: 15px;" @click="action('headmap')">热力图
          </Button>
          <Button type="primary" style="margin-bottom: 2px;margin-right: 15px;" @click="action('addNode')">添加临时任务
          </Button>
          <Button
            type="primary"
            style="margin-bottom: 2px;margin-right: 15px;"
            @click="action('addSignNode')"
          >添加会签
          </Button>
          <Button type="primary" style="margin-bottom: 2px;margin-right: 15px;" @click="action('flowImage')">流程图
          </Button>
          <Button
            type="primary"
            style="margin-bottom: 2px;margin-right: 15px;"
            @click="action('approvalHistory')"
          >审批历史
          </Button>
          <Button
            type="primary"
            style="margin-bottom: 2px;margin-right: 15px;"
            @click="action('print')"
          >打印
          </Button>

          <Button type="primary" style="margin-bottom: 2px;margin-right: 15px;" @click="go">
            <Icon type="md-close" />关闭
          </Button>

        </span>
      </div>
      <Modal
        v-model="transferTask.model"

        title="转办"
        width="50%"
        @on-cancel="handleTransferTaskReset"
        :transfer="false"
        :mask-closable="false"
      >
        <div>

          <Form ref="transferTask" :model="transferTask" :label-width="120" :rules="transferTaskRuleValidate">
            <FormItem label="备注/意见" prop="option">
              <Input v-model="transferTask.option" type="textarea" :autosize="{minRows: 2,maxRows: 5}" maxlength="60" show-word-limit   />
            </FormItem>
            <FormItem label="转办人">
              <Button
                v-if="singleUserData!=null && singleUserData.userNo!=null"
                v-model="singleUserData"
                type="primary"
                style="margin-left: 2px"
                color="primary"
                @click="delSingleUsers"
              >
                {{ singleUserData.fullname }} &nbsp;<Icon type="md-close" />

              </Button>
              <Button type="error" @click="selectSingleShowUsers">
                <Icon type="ios-contact" />
                处理人
              </Button>

            </FormItem>

          </Form>

        </div>
        <div slot="footer">
          <el-button type="primary"   @click="transferTaskHandler"  :loading="loading">确定</el-button>
          <el-button    @click="handleReset('transferTask')">取消</el-button>

        </div>
        <user-single-dialog
          :single-show.sync="singleShow"
          :on-ok="confirmDialogSingleEvent"
          :exist-data="singleUserData"
        />
      </Modal>
      <Modal
        :mask-closable="false"
        v-model="informed.informed"
        title="传阅表单"
        width="70%"
        :transfer="false"

      >
        <div>

          <Form ref="informed" :model="informed" :label-width="120" :rules="informedRuleValidate">
            <FormItem label="任务标题" prop="taskTitle">
              <el-input v-model="informed.taskTitle" />
            </FormItem>
            <FormItem label="备注/意见" prop="opinion">
              <Input maxlength="60" show-word-limit  v-model="informed.opinion" type="textarea" :autosize="{minRows: 2,maxRows: 5}" />

            </FormItem>
            <FormItem label="传阅人" prop="usersInfo">
              <Button
                v-for="(item,index) in informed.usersInfo"
                v-model="informed.usersInfo"
                type="primary"
                style="margin-left: 2px"
                color="primary"
                @click="delCommonUsers(index)"
              >
                {{ item.fullname }} &nbsp;<Icon type="md-close" />

              </Button>
              <Button type="error" @click="selectInformedUsers">
                <Icon type="ios-contact" />
                处理人
              </Button>

            </FormItem>

          </Form>
          <user-multiple-dialog
            :on-ok="confirmDialogEvent"
            :show.sync="show"
            :exist-data="existData"
            :node-index="task.nodeIndex"
            :alias="alias"
          />

        </div>
        <div slot="footer">
          <el-button type="primary"  @click="informedHandler"   :loading="loading">确定</el-button>
          <el-button  @click="handleReset('informed')" >取消</el-button>
        </div>
      </Modal>
      <Modal
        :mask-closable="false"
        v-model="handlerSequenceModel"
        title="备注/意见"
        width="70%"
        :transfer="false"
      >
        <div>
          <Form ref="taskSequenceForm" :model="taskSequenceForm" :label-width="130" :rules="taskSequenceRuleValidate">
            <FormItem label="下一个节点" prop="nextNode">
              <Tag v-for="item in sequenceNode"  size="large" color="primary">{{ item.taskName }}</Tag>
            </FormItem>
            <FormItem v-for="(item,index) in sequenceNode" :label="item.taskName" prop="usersIds">
              <Button
                v-for="(users,userIndex) in item.extObj"
                v-model="task.usersIds"
                size="small"
                type="primary"
                style="margin-left: 2px"
                @click="delSequenceUsers(index,userIndex)"
              >{{ users.fullname }}&nbsp;<Icon
                type="md-close"
              />
              </Button>

              <p>
                <Button type="error" @click="selectSequenceUsers(index)">
                  <Icon type="ios-contact" />

                </Button>
              </p>

            </FormItem>

            <FormItem v-model="taskSequenceForm.priority" label="优先级" prop="priority">
              <el-radio v-model="taskSequenceForm.priority" label="50">无</el-radio>
              <el-radio v-model="taskSequenceForm.priority" label="150">高</el-radio>
              <el-radio v-model="taskSequenceForm.priority" label="100">中</el-radio>
              <el-radio v-model="taskSequenceForm.priority" label="80">低</el-radio>

            </FormItem>

            <FormItem label="任务标题" prop="taskTitle">
              <el-input v-model="taskSequenceForm.taskTitle"  clearable/>
            </FormItem>
            <FormItem label="备注/意见" prop="opinion">
              <Input  v-model="taskSequenceForm.opinion" clearable type="textarea" :autosize="{minRows: 2,maxRows: 5}" ></Input>

            </FormItem>

          </Form>

        </div>
        <div slot="footer">
          <el-button type="primary"  @click="agreeTaskSequenceHandler('taskSequence')"    :loading="loading">确定</el-button>
          <el-button  @click="handleReset('taskSequence')" >取消</el-button>
        </div>

      </Modal>
      <Modal
        :mask-closable="false"
        v-model="handlerModel"
        title="备注/意见"
        width="70%"
        :transfer="false"
      >
        <div>

          <Form ref="task" :model="task" :label-width="130" :rules="ruleValidate">

            <FormItem label="下一个节点" prop="nextNode">
              <Tag v-for="item in task.nextNode" v-model="nextNode" size="large" color="primary">{{ item.taskName }}</Tag>
            </FormItem>
            <FormItem v-for="(item,index) in task.nextNode" :label="item.taskName" prop="usersIds">
              <Button
                v-for="(users,userIndex) in item.extObj"
                v-model="task.usersIds"
                size="small"
                type="primary"
                style="margin-left: 2px"
                @click="delUsers(index,userIndex)"
              >{{ users.fullname }}&nbsp;<Icon
                type="md-close"
              />
              </Button>

              <p>
                <Button type="error" @click="selectUsers(index)">
                  <Icon type="ios-contact" />

                </Button>
              </p>

            </FormItem>
            <FormItem v-model="task.priority" label="优先级" prop="priority">
              <el-radio v-model="task.priority" label="50">无</el-radio>
              <el-radio v-model="task.priority" label="150">高</el-radio>
              <el-radio v-model="task.priority" label="100">中</el-radio>
              <el-radio v-model="task.priority" label="80">低</el-radio>

            </FormItem>

            <FormItem label="任务标题" prop="taskTitle">
              <el-input v-model="task.taskTitle"  clearable/>
            </FormItem>
            <FormItem label="备注/意见" prop="opinion">
              <Input  maxlength="60" show-word-limit v-model="task.opinion" clearable type="textarea" :autosize="{minRows: 2,maxRows: 5}" />

            </FormItem>

          </Form>

        </div>
        <div slot="footer">
          <el-button type="primary"   @click="agreeHandler('task')"  :loading="loading">确定</el-button>
          <el-button    @click="handleReset('task')" >取消</el-button>
        </div>

      </Modal>
      <Modal
        :mask-closable="false"
        v-model="agreeAdHocSubProcess.show"
        title="备注/意见"
        width="70%"
        :transfer="false"
      >
        <div>

          <Form ref="agreeAdHocSubProcess" :model="agreeAdHocSubProcess" :label-width="120" :rules="ruleValidate">
            <Alert banner closable type="warning">下一个节点勾选那些，实例会创建那些节点。所选择的节点必须设置处理人...</Alert>
            <FormItem label="下一个节点" >
              <el-checkbox-group  v-model="agreeAdHocSubProcess.nextNodeName" @change="handleCheckedNextNodeChange">

                <el-checkbox v-for="item in agreeAdHocSubProcess.nextNodeNameOptions"

                             :label="item"
                             :key="item"
                >
              {{item}}
                </el-checkbox>
              </el-checkbox-group>


            </FormItem>
            <FormItem v-for="(item,index) in agreeAdHocSubProcess.nextNode" :label="item.taskName" prop="usersIds" >
              <Button
                v-for="(users,userIndex) in item.extObj"
                v-model="agreeAdHocSubProcess.usersIds"
                size="small"
                type="primary"
                style="margin-left: 2px"
                @click="delUsers(index,userIndex)"
              >{{ users.fullname }}&nbsp;<Icon
                type="md-close"
              />
              </Button>

              <p>
                <Button type="error" @click="selectAgreeAdHocSubProcessUsers(index)">
                  <Icon type="ios-contact" />
                </Button>
              </p>

            </FormItem>
            <FormItem v-model="agreeAdHocSubProcess.priority" label="优先级" prop="priority">
              <el-radio v-model="agreeAdHocSubProcess.priority" label="50">无</el-radio>
              <el-radio v-model="agreeAdHocSubProcess.priority" label="150">高</el-radio>
              <el-radio v-model="agreeAdHocSubProcess.priority" label="100">中</el-radio>
              <el-radio v-model="agreeAdHocSubProcess.priority" label="80">低</el-radio>

            </FormItem>

            <FormItem label="任务标题" prop="taskTitle">
              <el-input v-model="agreeAdHocSubProcess.taskTitle" />
            </FormItem>
            <FormItem label="备注/意见" prop="opinion">
              <Input maxlength="60" show-word-limit  v-model="agreeAdHocSubProcess.opinion" type="textarea" :autosize="{minRows: 2,maxRows: 5}" />

            </FormItem>

          </Form>

        </div>
        <div slot="footer">
          <el-button type="primary"   @click="agreeAdHocSubProcessHandle('agreeAdHocSubProcess')"  :loading="loading">确定</el-button>
          <el-button  @click="handleReset('agreeAdHocSubProcess')" >取消</el-button>

        </div>

      </Modal>

      <Modal
        :mask-closable="false"
        v-model="headMap.show"
        title="热力图"
        width="85%"
        :transfer="false"
      >
        <iframe
          id="iframe"
          width="100%"
          style="min-height: 600px"
          height="100%"
          frameborder="0"
          align="center"
          allowfullscreen="true"
          allow="autoplay"
          :src="headMap.src"
        />
        <div slot="footer" />
      </Modal>
      <Modal
        :mask-closable="false"
        v-model="opinion.show"
        title="意见"
        width="85%"
        :transfer="false"
      >
        <Table
          ref="selection"
          border
          highlight-row
          height="450"
          :columns="opinion.tableColumns"
          :data="opinion.tableData"
          style="padding-left: 10px;padding-top: 10px"
        />
        <div slot="footer" />
      </Modal>
      <Modal
        :mask-closable="false"
        v-model="flowImage.show"
        title="流程图"
        width="85%"
        :transfer="false"
      >
        <iframe
          id="flowImageframe"
          width="100%"
          style="min-height: 600px"
          height="100%"
          frameborder="0"
          align="center"
          allowfullscreen="true"
          allow="autoplay"
          :src="flowImage.src"
        />
        <div slot="footer" />
      </Modal>
      <Modal
        :mask-closable="false"
        v-model="backToNodeForm.show"
        title="退回"
        width="45%"
        :transfer="false"
      >

        <Form ref="backToNodeForm" :model="backToNodeForm" :label-width="120" :rules="backToNodFormRuleValidate">

          <FormItem label="退回节点" prop="newActivityId">
            <Select v-model="backToNodeForm.newActivityId" style="width:200px" @on-change="backToNodeChange">
              <Option v-for="item in backToNodeForm.nodeArray" :key="item.id" :value="item.id">{{ item.name }}</Option>
            </Select>
            <Button type="error" @click="freedomChoice">
              自由选择
            </Button>
          </FormItem>
          <FormItem label="处理人">
            <Button
              v-if="singleUserData!=null && singleUserData.userNo!=null"
              v-model="singleUserData"
              type="primary"
              style="margin-left: 2px"
              color="primary"
              @click="delSingleUsers"
            >
              {{ singleUserData.fullname }} &nbsp;<Icon type="md-close" />

            </Button>
            <Button type="error" @click="selectSingleShowUsers">
              <Icon type="ios-contact" />
              处理人
            </Button>

          </FormItem>
          <FormItem v-model="backToNodeForm.priority" label="优先级" prop="priority">
            <el-radio v-model="backToNodeForm.priority" label="50">无</el-radio>
            <el-radio v-model="backToNodeForm.priority" label="150">高</el-radio>
            <el-radio v-model="backToNodeForm.priority" label="100">中</el-radio>
            <el-radio v-model="backToNodeForm.priority" label="80">低</el-radio>

          </FormItem>

          <FormItem label="任务标题" prop="taskTitle">
            <el-input v-model="backToNodeForm.taskTitle" />
          </FormItem>
          <FormItem label="备注/意见" prop="option">
            <Input maxlength="60" show-word-limit  v-model="backToNodeForm.option" type="textarea" :autosize="{minRows: 2,maxRows: 5}" />

          </FormItem>

        </Form>
        <div slot="footer">


          <el-button type="primary"   @click="backToNodeHandler('backToNode')"  :loading="loading">确定</el-button>
          <el-button  @click="handleReset('backToNode')" >取消</el-button>


        </div>
      </Modal>
      <Modal
        :mask-closable="false"
        v-model="transactionUrge.show"
        title="特事特办"
        width="65%"
        @on-cancel="handleTransactionUrgeReset"
        :transfer="false"
      >

        <Form ref="transactionUrge" :model="transactionUrge" :label-width="120" :rules="transactionUrgeRuleValidate">

          <FormItem label="选择" prop="newActivityId">
            <Select v-model="transactionUrge.newActivityId" style="width:200px">
              <Option v-for="item in transactionUrgeData.nodeArray" :key="item.id" :value="item.id">{{ item.name }}</Option>
            </Select>

          </FormItem>
          <FormItem label="处理人">
            <Button
              v-if="singleUserData!=null && singleUserData.userNo!=null"
              v-model="singleUserData"
              type="primary"
              style="margin-left: 2px"
              color="primary"
              @click="delSingleUsers"
            >
              {{ singleUserData.fullname }} &nbsp;<Icon type="md-close" />

            </Button>
            <Button type="error" @click="selectSingleShowUsers">
              <Icon type="ios-contact" />
              处理人
            </Button>

          </FormItem>
          <FormItem label="备注/意见" prop="option">
            <Input v-model="transactionUrge.option" type="textarea" :autosize="{minRows: 2,maxRows: 5}" maxlength="60" show-word-limit  />

          </FormItem>
          <FormItem label="任务标题" prop="taskTitle">
            <el-input v-model="transactionUrge.taskTitle" />
          </FormItem>

          <FormItem v-model="transactionUrge.priority" label="优先级" prop="priority">
            <el-radio v-model="transactionUrge.priority" label="50">无</el-radio>
            <el-radio v-model="transactionUrge.priority" label="150">高</el-radio>
            <el-radio v-model="transactionUrge.priority" label="100">中</el-radio>
            <el-radio v-model="transactionUrge.priority" label="80">低</el-radio>

          </FormItem>

        </Form>
        <div slot="footer">

          <el-button type="primary"   @click="transactionUrgeHandler('transactionUrge')"   :loading="loading">确定</el-button>
          <el-button  @click="handleReset('transactionUrge')" >取消</el-button>


        </div>
      </Modal>
      <Modal
        :mask-closable="false"
        v-model="addNode.show"
        title="添加临时节点"
        width="45%"
        :transfer="false"
      >

        <Form ref="addNode" :model="addNode" :label-width="120" :rules="addNodeRuleValidate">

          <FormItem label="目标节点" prop="nextId">
            <Select v-model="addNode.nextId" style="width:200px">
              <Option v-for="item in transactionUrgeData.nodeArray" :key="item.id" :value="item.id">{{ item.name }}</Option>
            </Select>

          </FormItem>
          <FormItem label="处理人">
            <Button
              v-if="singleUserData!=null && singleUserData.userNo!=null"
              v-model="singleUserData"
              type="primary"
              style="margin-left: 2px"
              color="primary"
              @click="delSingleUsers"
            >
              {{ singleUserData.fullname }} &nbsp;<Icon type="md-close" />

            </Button>
            <Button type="error" @click="selectSingleShowUsers">
              <Icon type="ios-contact" />
              处理人
            </Button>

          </FormItem>
          <FormItem label="任务名称" prop="userTaskName">
            <Input v-model="addNode.userTaskName" />
          </FormItem>
        </Form>
        <div slot="footer">

          <el-button type="primary"    @click="addNodeHandler('addNode')" :loading="loading">确定</el-button>
          <el-button   @click="handleReset('addNode')">取消</el-button>

        </div>
      </Modal>
      <Modal
        :mask-closable="false"
        v-model="addSign.show"
        title="添加会签节点"
        width="45%"
        :transfer="false"
      >

        <Form ref="addSign" :model="addSign" :label-width="120" :rules="addSignRuleValidate">

          <FormItem label="目标节点" prop="nextId">
            <Select v-model="addSign.nextId" style="width:200px">
              <Option v-for="item in transactionUrgeData.nodeArray" :key="item.id" :value="item.id">{{ item.name }}</Option>
            </Select>

          </FormItem>

          <FormItem label="加签类型" prop="parallel">
            <RadioGroup v-model="addSign.parallel">
              <Radio label="true">
                <span>串行</span>
              </Radio>
              <Radio label="false">
                <span>并行</span>
              </Radio>
            </RadioGroup>

          </FormItem>
          <FormItem label="比例" prop="signScale">
            <Select v-model="addSign.signScale" style="width:200px">
              <Option v-for="item in signType" :key="item.lable" :value="item.lable">{{ item.value }}</Option>
            </Select>

          </FormItem>
          <FormItem label="通过" prop="pass">
            <Select v-model="addSign.pass" style="width:200px">
              <Option value="next">流转后置节点</Option>
              <Option value="pre">回退前置节点</Option>
            </Select>
          </FormItem>
          <FormItem label="拒绝" prop="unPass">
            <Select v-model="addSign.unPass" style="width:200px">
              <Option value="next">流转后置节点</Option>
              <Option value="pre">回退前置节点</Option>
            </Select>
          </FormItem>
          <FormItem label="会签人全部参与" prop="allStrage">
            <RadioGroup v-model="addSign.allStrage">
              <Radio label="true">
                <span>是</span>
              </Radio>
              <Radio label="false">
                <span>否</span>
              </Radio>
            </RadioGroup>

          </FormItem>
          <FormItem label="策略" prop="signType">
            <RadioGroup v-model="addSign.signType">
              <Radio label="scale">
                <span>比例通过制</span>
              </Radio>
            </RadioGroup>

          </FormItem>

          <FormItem label="处理人">

            <Button
              v-for="(item,index) in addSign.usersInfo"
              v-model="addSign.usersInfo"
              type="primary"
              style="margin-left: 2px"
              color="primary"
              @click="delCommonUsers(index)"
            >
              {{ item.fullname }} &nbsp;<Icon type="md-close" />

            </Button>

            <Button
              v-if="singleUserData!=null && singleUserData.userNo!=null"
              v-model="singleUserData"
              type="primary"
              style="margin-left: 2px"
              color="primary"
              @click="delSingleUsers"
            >
              {{ singleUserData.fullname }} &nbsp;<Icon type="md-close" />

            </Button>
            <Button type="error" @click="selectAddSignUsers">
              <Icon type="ios-contact" />
              处理人
            </Button>

          </FormItem>
          <FormItem label="任务名称" prop="userTaskName">
            <Input v-model="addSign.userTaskName" />
          </FormItem>
        </Form>
        <div slot="footer">

          <el-button type="primary"   @click="addSignHandler('addSign')"  :loading="loading">确定</el-button>
          <el-button  @click="handleReset('addSign')" >取消</el-button>


        </div>
      </Modal>
      <Card>
        <p slot="title">
          <span v-if="jsonData.config!=null">{{ jsonData.config.formName }}</span>

        </p>
        <div v-if="jsonData.config!=null" class="container">
          <fm-generate-form
            ref="generateForm"
            :data="jsonData"
            :remote="remoteFuncs"
            :value="editData"
            :remote-option="dynamicData"
          />

        </div>

      </Card>
    </Card>
  </div>

</template>

<script>
import { renderByTaskId, getTaskBtn, getNextNode, completeTask,completeAdHoc } from '@/api/analy'
import { success } from '@/api/msg'
import { informedTask, transferTask, invalidTask,
  opinionTask, getTransactionUrge,
  changeActivity, getOutgoingFlows, addNodeOperate,
  addSignOperate,
  saveform,
  getBackNode,
  getBackNodeUser
} from '@/api/action'
import userMultipleDialog from '@/views/components/org/userMultipleDialog'
import userSingleDialog from '@/views/components/org/userSingleDialog'

import Footer from '../../../common/footer'

export default {
  name: 'Task',
  components: {
    Footer,
    userMultipleDialog,
    userSingleDialog
  },

  data() {
    return {
      loading: false,
      fromIndex: false,
      taskId: '',
      processDefinitionId: '',
      processInstanceId: '',
      tableHeight: '',
      alias: '',
      handlerModel: false,
      handlerSequenceModel: false,
      isSpinShow: true,
      show: false,
      singleShow: false,
      jsonData: {},
      editData: {},
      remoteFuncs: {},
      singleUserData: {},
      dynamicData: {},
      taskBtns: [],
      multiInstanceTaskBtns: [],
      taskSequence: [],
      taskSequenceForm: {
        taskTitle:'',
        userInfo:[],
        taskName: '',
        choose: true,
        taskId: '',
        opinion: '',
        formType: 'inner',
        actionName: '',
        action: '',
        nodeType: '',
        usersIds: [],
        userNames: [],
        nextNode: [],
        chooseNode: '',
        chooseNodeUser: '',
        formData: '',
        nodeIndex: 0,
        priority: '50',

      },
      existData: [],
      nextNode: [],
      sequenceNode: [],
      transferTask:
          {
            usersInfo: {},
            option: '',
            taskId: '',
            show: false,
            model: false
          },
      headMap:
          {
            show: false,
            src: '',
            base: process.env.VUE_APP_BASE_BPM_API + '/head-map/index.html?processefinitionId='
          },
      opinion:
          {
            show: false,
            tableColumns: [
              {
                title: '任务名称',
                key: 'nodeName'
              },
              {
                title: '创建时间',
                key: 'createTime'
              },
              {
                title: '审批时间',
                key: 'completeTime'
              },
              {
                title: '执行人',
                render: (h, params) => {
                  var html = '-'
                  var node = this.opinion.tableData[params.index]
                  if (node.a1FlowTaskTrajectoryEntity) {
                    html = node.a1FlowTaskTrajectoryEntity.userName
                  } else {
                    html = node.auditor
                  }
                  if(!html){
                    if(node.identityLinks){
                      html=node.identityLinks
                    }

                  }
                  return h('span', html)
                }
              },
              {
                title: '任务标题',
                render: (h, params) => {
                  var html = '-'
                  var node = this.opinion.tableData[params.index]
                  html = node.a1FlowTaskTrajectoryEntity.title
                  return h('span', html)
                }
              },
              {
                title: '备注/意见',
                render: (h, params) => {
                  var html = '-'
                  var node = this.opinion.tableData[params.index]
                  html = node.a1FlowTaskTrajectoryEntity.opinion
                  return h('span', html)
                }
              },
              {
                title: '状态说明',
                render: (h, params) => {
                  var html = '-'
                  var node = this.opinion.tableData[params.index]
                  html = node.a1FlowTaskTrajectoryEntity.statusVal
                  return h('span', html)
                }
              }

            ],
            tableData: []
          },
      flowImage:
          {
            show: false,
            src: '',
            base: process.env.VUE_APP_BASE_BPM_API + '/view/tab.html?fireHoverAction=true&table=false' + '&instId='
          },
      transactionUrge:
            {
              show: false,
              newActivityId: '',
              operate: 'transactionUrge',
              taskTitle: '',
              taskId: '',
              option: '',
              priority: '50',
              usersInfo: {}
            },
      transactionUrgeData: {
        nodeArray: []
      },
      addNode: {
        show: false,
        nextId: '',
        userTaskName: ''
      },
      signType: [
        { lable: '10', value: '10%' },
        { lable: '20', value: '20%' },
        { lable: '30', value: '30%' },
        { lable: '40', value: '40%' },
        { lable: '50', value: '50%' },
        { lable: '60', value: '60%' },
        { lable: '70', value: '70%' },
        { lable: '80', value: '80%' },
        { lable: '90', value: '90%' },
        { lable: '100', value: '100%' }
      ],
      addSign: {
        show: false,
        all: false,
        parallel: 'false',
        allStrage: 'false',
        doUserId: '',
        pass: 'next',
        nextId: '',
        signScale: '',
        signType: 'scale',
        unPass: 'next',
        userTaskName: '',
        usersInfo: []

      },
      sequence:{
        users:[]
      },
      addSignRuleValidate: {
        nextId: [
          { required: true, message: '目标节点必须填写', trigger: 'blur' }
        ],
        signType: [
          { required: true, message: '策略必填', trigger: 'blur' }
        ],
        signScale: [
          { required: true, message: '比例必填', trigger: 'blur' }
        ],
        userTaskName: [
          { required: true, message: '任务名称必填', trigger: 'blur' }
        ]
      },
      informed: {
        show: false,
        informed: false,
        usersInfo: [],
        opinion: '',
        taskTitle: '',
        taskId: ''

      },
      agreeAdHocSubProcess: {
        show: false,
        usersIds: [],
        userNames: [],
        nextNode: [],
        nextNodeName: [],
        nextNodeNameOptions: [],
        taskId:"",
        usersInfo:[],
        nodeIndex: 0,
        priority: '50',
        taskTitle: '',
        option: '',
        chooseNode: '',
        chooseNodeUser: '',
      },
      backToNodeForm: {
        show: false,
        usersInfo: [],
        option: '',
        taskTitle: '',
        taskId: '',
        priority: '50',
        newActivityId: '',
        operate: 'backToNode',
        nodeArray: []
      },
      backToNodFormRuleValidate: {
        newActivityId: [
          { required: true, message: '退回节点必须填写', trigger: 'blur' }
        ],
        option: [
          { required: true, message: '意见必须填写', trigger: 'blur' }
        ]
      },
      scopeType:"",
      monitor:false,

      tmpTaskInfo:{ taskTitle:'',},
      task: {
        taskName: '',
        taskId: '',
        opinion: '',
        formType: 'inner',
        actionName: '',
        action: '',
        nodeType: '',
        usersIds: [],
        userNames: [],
        nextNode: [],
        chooseNode: '',
        chooseNodeUser: '',
        formData: '',
        nodeIndex: 0,
        priority: '50',
        taskTitle: ''

      },
      ruleValidate: {
        opinion: [
          { required: true, message: '意见必须填写', trigger: 'blur' }
        ]
      },
      taskSequenceRuleValidate: {
        opinion: [
          { required: true, message: '意见必须填写', trigger: 'blur' }
        ]
      },
      backToNodeRuleValidate: {
        opinion: [
          { required: true, message: '意见必须填写', trigger: 'blur' }
        ]
      },

      informedRuleValidate: {
        taskTitle: [
          { required: true, message: '标题必须填写', trigger: 'blur' }
        ],
        opinion: [
          { required: true, message: '意见必须填写', trigger: 'blur' }
        ]

      },
      transferTaskRuleValidate: {
        usersInfo: [
          { required: true, message: '转办人必须填写', trigger: 'blur' }
        ],
        option: [
          { required: true, message: '意见必须填写', trigger: 'blur' }
        ]

      },
      transactionUrgeRuleValidate: {
        newActivityId: [
          { required: true, message: '节点必须填写', trigger: 'blur' }
        ],
        usersInfo: [
          { required: true, message: '人员必须填写', trigger: 'blur' }
        ],
        option: [
          { required: true, message: '意见必须填写', trigger: 'blur' }
        ]

      },
      addNodeRuleValidate: {
        userTaskName: [
          { required: true, message: '任务名称必填', trigger: 'blur' }
        ],
        nextId: [
          { required: true, message: '目标节点必填', trigger: 'blur' }
        ]

      }
    }
  },
  mount() {

  },

  created() {
    var query = this.$route.query
    var queryTaskId=query.taskId;
    var monitor=query.monitor;
    if (monitor){
      this.monitor=monitor;
    }
    if ( query.taskId) {
      queryTaskId=query.taskId;
    }else{
      queryTaskId=this.taskParam;
      this.fromIndex=true
    }
    this.taskId =queryTaskId
    this.task.taskId = queryTaskId
    this.scopeType = query.scopeType

    this.initData();


  },
  props: {
    taskParam: {
      type: String,
      default: ""
    }
  },
  watch: {
    taskParam() {
      if (this.taskParam){
        this.taskId =this.taskParam
        this.task.taskId = this.taskParam
        this.fromIndex=true;
        this.initData();

      } else{

        this.jsonData={}
        this.editData={}
        this.fromIndex=false;
        this.restartShow()

      }

    },
    jsonData: {
      handler(newValue, oldValue) {
        if (newValue) {
          this.getFormData()
        }
      },
      deep: true
    }
  },

  methods: {
    restartShow:function(){
      this.handlerModel=false
      this.agreeAdHocSubProcess.show=false
      this.headMap.show=false
      this.opinion.show=false
      this.flowImage.show=false
      this.backToNodeForm.show=false
      this.transactionUrge.show=false
      this.addNode.show=false
      this.addSign.show=false
    },
    initData:function(){
      this.getTaskBtn(this.taskId)
      this.renderByTaskId(this.taskId)

      this.$nextTick(() => {
        try {
          this.$refs['task'].validate((valid) => {
          })
        } catch (e) {

        }
      })
      if (this.scopeType){

      }else{
        this.getNextNode()
      }
      this.getFormData();
      this.task.opinion='';
      this.taskSequenceForm.opinion='';
      this.agreeAdHocSubProcess.opinion='';
    },
    triggerRuleValidate: function() {

    },
    handleCheckedNextNodeChange:function(data){
    },
    freedomChoice: function() {
      getTransactionUrge(this.taskId).then((response) => {
        if (response.code == 0) {
          this.backToNodeForm.nodeArray = response.data
        }
      })
    },
    backToNodeChange: function(nodeId) {
      getBackNodeUser(this.taskId, nodeId).then((response) => {
        if (response.code == 0) {
          if (response.data && response.data.length > 0) {
            if (response.data[0].assigneeName && response.data[0].assignee) {
              var assigneeName = response.data[0].assigneeName
              var assignee = response.data[0].assignee
              this.singleUserData = { 'userNo': assignee, 'fullname': assigneeName }
              this.backToNodeForm.usersInfo = this.singleUserData
            } else {
              this.singleUserData = {}
              this.backToNodeForm.usersInfo = {}
            }
          } else {
            this.singleUserData = {}
            this.backToNodeForm.usersInfo = {}
          }
        }
      })
    },
    confirmDialogEvent: function(data) {
      if (data) {
        switch (this.alias) {
          case 'agree':// 普通任务正常办理

            this.task.nextNode[this.task.nodeIndex].extObj = data
            break
          case 'informed':
            this.informed.usersInfo = data
            this.existData = data
            break
          case 'transferTask':
            this.transferTask.usersInfo = data
            this.existData = data
            break
          case 'transactionUrge':
            this.transactionUrge.usersInfo = data
            this.existData = data
            break
          case 'agreeAdHocSubProcess':

            this.agreeAdHocSubProcess.nextNode[this.task.nodeIndex].extObj = data
            break
          case 'addSignNode':
            this.addSign.usersInfo = data
            this.existData = data
            break
          case 'sequence':
            this.sequence.users = data
            this.sequenceNode[0].extObj=data
            this.taskSequence.userInfo=data;
            break
          default:
        }
      }
    },
    confirmDialogSingleEvent: function(data) {
      if (data) {
        this.singleUserData = data
      }
    },
    confirmInformedDialogEvent: function(data) {
      if (data) {
      }
    },

    selectUsers: function(index) {
      this.task.nodeIndex=index
      var users=   this.task.nextNode[index].extObj
      this.existData=users
      this.show = true

    },
    selectSequenceUsers: function(index) {
      var users= this.sequenceNode[0].extObj ;
      this.existData=[]
      if (users){
        this.existData=users
      }
      this.show = true

    },
    selectAddSignUsers:function(){
      try {
        this.existData=this.addSign.usersInfo;

      }catch (e) {
        this.existData=[]
      }
      this.show = true
    },
    selectInformedUsers:function(){
      try {
        this.existData=this.informed.usersInfo;

      }catch (e) {
        this.existData=[]
      }
      this.show = true
    },
    selectAgreeAdHocSubProcessUsers: function(index) {
      this.task.nodeIndex=index;
      try {
        this.existData=this.agreeAdHocSubProcess.nextNode[index].extObj

      }catch (e) {
        this.existData=[]
      }
      this.show = true
    },
    selectSingleShowUsers: function() {
      this.singleShow = true
    },
    delUsers: function(index, userIndex) {
      this.task.nextNode[index].extObj.splice(userIndex, 1)
    },
    delSequenceUsers: function(index, userIndex) {
      this.sequenceNode[0].extObj.splice(userIndex, 1)
    },
    delCommonUsers: function(index) {
      this.informed.usersInfo.splice(index, 1)
      this.addSign.usersInfo.splice(index, 1)
      this.existData.splice(index, 1)
    },
    delSingleUsers: function(index) {
      this.singleUserData = {}
    },
    getFormData: function() {
      if (this.$refs.generateForm) {
        this.$refs.generateForm.getData().then(data => {
          this.task.formData = JSON.stringify(data)
          return data
        }).catch(e => {
        })
      }

    },
    backToNodeHandler: function() {
      new Promise((resolve, reject) => {
        if (this.singleUserData && this.singleUserData.userNo) {
          this.$refs['backToNodeForm'].validate((valid) => {
            if (valid) {
              const obj = JSON.parse(JSON.stringify(this.backToNodeForm))
              delete (obj['show'])
              delete (obj['nodeArray'])
              delete (obj['usersInfo'])
              obj['userId'] = this.singleUserData.userNo
              obj['userName'] = this.singleUserData.fullname
              obj['taskId'] = this.taskId
              delete (obj['usersInfo'])
              this.loading=true
              changeActivity(obj).then((response) => {
                if (response.code == 0) {
                  this.go()
                } else {
                  this.$message({"duration":'800',message:response.msg,type:'warning',customClass:'zZindex'});

                }
                this.loading=false
              })
            } else {

            }
          })
        } else {
          that.$message({message:'请选择处理人',type:'warning',customClass:'zZindex'});
        }
      })
    },
    transactionUrgeHandler: function() {
      new Promise((resolve, reject) => {
        if (this.singleUserData && this.singleUserData.userNo) {
          this.$refs['transactionUrge'].validate((valid) => {
            if (valid) {
              this.changeActivityAction()
            } else {

            }
          })
        } else {
          this.$message({"duration":'800',message:'请选择处理人',type:'warning',customClass:'zZindex'});

        }
      })
    },
    afterAddSignHandler: function() {
      this.addSign.all = false
      this.addSign.parallel = 'false'
      this.addSign.allStrage = 'false'
      this.addSign.doUserId = ''
      this.addSign.pass = 'next'
      this.addSign.nextId = ''
      this.addSign.signScale = ''
      this.addSign.signType = 'scale'
      this.addSign.unPass = 'next'
      this.addSign.userTaskName = ''
      this.addSign.usersInfo = []
    },
    addSignHandler: function() {
      this.loading=false;
      new Promise((resolve, reject) => {
        if (this.addSign.usersInfo && this.addSign.usersInfo.length > 0) {
          this.$refs['addSign'].validate((valid) => {
            if (valid) {
              const obj = JSON.parse(JSON.stringify(this.addSign))
              delete (obj['show'])
              obj['taskId'] = this.taskId
              this.loading=true;
              addSignOperate(obj).then((response) => {
                if (response.code == 0) {
                  this.$message({"duration":'800',message:'操作成功',type:'success',customClass:'zZindex'});
                  this.addSign.show = false
                  this.afterAddSignHandler()
                  this.go();
                } else {
                  this.$message({"duration":'800',message: response.msg,type:'success',customClass:'zZindex'});

                }
                this.loading=false;
              })
            } else {

            }
          })
        } else {
          this.$message({"duration":'800',message:'请选择处理人',type:'warning',customClass:'zZindex'});
        }
      })
    },
    addNodeHandler: function() {
      this.loading=false;
      new Promise((resolve, reject) => {
        if (this.singleUserData && this.singleUserData.userNo) {
          this.$refs['addNode'].validate((valid) => {
            if (valid) {
              // addNodeOperate
              const obj = JSON.parse(JSON.stringify(this.addNode))
              delete (obj['show'])
              obj['taskId'] = this.taskId
              obj['users'] = this.singleUserData.userNo
              this.loading=true;
              addNodeOperate(obj).then((response) => {
                if (response.code == 0) {
                  this.$message({"duration":'800',message:'操作成功',type:'success',customClass:'zZindex'});
                  this.addNode.show = false
                  this.go();
                } else {
                  this.$message({"duration":'800',message:response.msg,type:'warning',customClass:'zZindex'});
                }
                this.loading=false;
              })
            } else {

            }
          })
        } else {
          this.$message({"duration":'800',message:'请选择处理人',type:'warning',customClass:'zZindex'});

        }
      })
    },
    changeActivityAction: function() {
      this.loading=false;
      const obj = JSON.parse(JSON.stringify(this.transactionUrge))
      delete (obj['show'])
      obj['userId'] = this.singleUserData.userNo
      obj['userName'] = this.singleUserData.fullname
      obj['taskId'] = this.taskId
      delete (obj['usersInfo'])
      this.loading=true;
      changeActivity(obj).then((response) => {
        if (response.code == 0) {
          this.go()
        } else {
          this.$message({"duration":'800',message:response.msg,type:'warning',customClass:'zZindex'});

        }
        this.loading=false;
      })
    },
    completeSequenceTask: function() {
      this.loading=false;
      new Promise((resolve, reject) => {
        if(this.sequenceNode[0]){
          this.taskSequenceForm.chooseNode=this.sequenceNode[0].chooseNode
          this.taskSequenceForm.chooseNodeUser=this.sequenceNode[0].chooseNodeUser
        }

        this.taskSequenceForm.taskId=this.task.taskId;
        this.taskSequenceForm.formData=  this.task.formData
        this.loading=true;
        completeTask(this.taskSequenceForm).then((response) => {
          if (response.code == 0) {
            this.handlerSequenceModel=false;
            this.go()
          }else{
            this.$message({"duration":'800',message:response.msg,type:'warning',customClass:'zZindex'});

          }
          this.loading=false;

        })
      })
    },

    agreeTaskSequenceHandler:function(){
      //taskSequence
      this.loading=false;
      this.$refs['taskSequenceForm'].validate((valid) => {
        if (valid) {
          var nextNodeStr = ''
          var nextNodeStrUser = ''
          for (var i = 0; i < this.sequenceNode.length; i++) {
            nextNodeStr += this.sequenceNode[i].taskId
            if (i < this.sequenceNode.length - 1) {
              nextNodeStr += ','
            }

            if (this.sequenceNode[i].extObj) {
              for (var j = 0; j < this.sequenceNode[i].extObj.length; j++) {
                nextNodeStrUser += this.sequenceNode[i].extObj[j].userNo
                if (j < this.sequenceNode[i].extObj.length - 1) {
                  nextNodeStrUser += ','
                }
              }
              if (this.sequenceNode.length > 1 && i < this.sequenceNode.length - 1) {
                nextNodeStrUser += '_'
              }
            }
          }
          if (this.sequenceNode && this.sequenceNode[0]){
            this.sequenceNode[0].chooseNode = nextNodeStr
            this.sequenceNode[0].chooseNodeUser = nextNodeStrUser
          }
          const that = this
          setTimeout(function() {
            that.completeSequenceTask()
          }, 300)
        } else {
          this.$message({"duration":'800',message:'表单校验不通过',type:'warning',customClass:'zZindex'});

        }
      })
    },
    agreeAdHocSubProcessHandle: function() {
      this.loading=false;
      this.$refs['agreeAdHocSubProcess'].validate((valid) => {
        var nextNodeName= this.agreeAdHocSubProcess.nextNodeName
        if (valid) {
          var nextNodeStr = ''
          var nextNodeStrUser = ''
          for (var i = 0; i < this.nextNode.length; i++) {
            var taskName= this.nextNode[i].taskName
            var flag=false;
            for (var j = 0; j < nextNodeName.length; j++) {
              if (nextNodeName[j]==taskName) {
                flag=true;
                break
              }
            };


            if(flag){
              nextNodeStr += this.nextNode[i].taskId
              if (i < this.nextNode.length - 1) {
                nextNodeStr += ','
              }

              if (this.nextNode[i].extObj) {
                for (var j = 0; j < this.nextNode[i].extObj.length; j++) {
                  nextNodeStrUser += this.nextNode[i].extObj[j].userNo
                  if (j < this.nextNode[i].extObj.length - 1) {
                    nextNodeStrUser += ','
                  }
                }
                if (this.nextNode.length > 1 && i < this.nextNode.length - 1) {
                  nextNodeStrUser += '_'
                }
              }
            }
          }

          var userNodeReg=/,$/gi;//
          var userReg=/_$/gi;//
          nextNodeStrUser= nextNodeStrUser.replace(userReg,"");
          nextNodeStr= nextNodeStr.replace(userNodeReg,"");
          this.agreeAdHocSubProcess.chooseNode = nextNodeStr.replace(userReg,"");
          this.agreeAdHocSubProcess.chooseNodeUser = nextNodeStrUser
          const that = this
          setTimeout(function() {
             that.completeAdHoc()
          }, 300)
        } else {
        }
      })
    },
    agreeHandler: function() {
      this.loading=false;
      this.$refs['task'].validate((valid) => {
        if (valid) {
          var nextNodeStr = ''
          var nextNodeStrUser = ''
          for (var i = 0; i < this.nextNode.length; i++) {
            nextNodeStr += this.nextNode[i].taskId
            if (i < this.nextNode.length - 1) {
              nextNodeStr += ','
            }

            if (this.nextNode[i].extObj) {
              for (var j = 0; j < this.nextNode[i].extObj.length; j++) {
                nextNodeStrUser += this.nextNode[i].extObj[j].userNo
                if (j < this.nextNode[i].extObj.length - 1) {
                  nextNodeStrUser += ','
                }
              }
              if (this.nextNode.length > 1 && i < this.nextNode.length - 1) {
                nextNodeStrUser += '_'
              }
            }
          }
          this.task.chooseNode = nextNodeStr
          this.task.chooseNodeUser = nextNodeStrUser
          const that = this
          this.loading=true;
          setTimeout(function() {

            that.completeTask();
            that.loading=false;
          }, 300)
        } else {
          this.handlerModel = true
        }
      })
    },
    informedTask: function() {
      this.loading=false;
      new Promise((resolve, reject) => {
        this.informed.taskId = this.taskId
        this.$refs['informed'].validate((valid) => {
          if (valid) {
            this.informedTaskAction()
          } else {

          }
        })
      })
    },
    transferTaskAction: function() {
      this.loading=false;
      new Promise((resolve, reject) => {
        this.transferTask.taskId = this.taskId
        if (this.singleUserData && this.singleUserData.userNo) {
          this.$refs['transferTask'].validate((valid) => {
            if (valid) {
              this.doTransferTaskAction()
            } else {

            }
          })
        } else {
          this.$message({"duration":'800',message:'请选择转办人',type:'warning',customClass:'zZindex'});

        }
      })
    },
    afterInformedTaskAction: function() {
      this.informed.informed = false
      this.informed.opinion = ''
      this.informedReset()
      this.$message({"duration":'800',message:'传阅成功',type:'warning',customClass:'zZindex'});

    },
    afterTransferTaskAction: function() {
      this.go()
    },
    informedTaskAction: function() {
      this.loading=false;
      const obj = JSON.parse(JSON.stringify(this.informed))
      delete (obj['show'])
      delete (obj['informed'])
      this.loading=true;
      informedTask(obj).then((response) => {
        if (response.code == 0) {
          this.afterInformedTaskAction()
        } else {
          this.$message({"duration":'800',message:response.msg,type:'warning',customClass:'zZindex'});

        }
        this.loading=false;
      })
    },
    doTransferTaskAction: function() {
      this.loading=false;
      const obj = JSON.parse(JSON.stringify(this.transferTask))
      obj['usersInfo'] = this.singleUserData
      delete (obj['show'])
      delete (obj['model'])
      transferTask(obj).then((response) => {
        if (response.code == 0) {
          this.$message({"duration":'800',message:'转办成功',type:'warning',customClass:'zZindex'});
          this.transferTask.model=false
          const that = this
          this.loading=true;
          setTimeout(function() {
            that.afterTransferTaskAction()
            that.loading=false;
          }, 300)
        } else {
          this.$message({"duration":'800',message:response.msg,type:'warning',customClass:'zZindex'});


        }
      })
    },
    completeTask: function() {
      this.loading=false;
      new Promise((resolve, reject) => {
        const objB = JSON.parse(JSON.stringify(this.task))
        objB['monitor']=this.monitor
        delete (objB['usersIds'])
        delete (objB['userNames'])
        delete (objB['nextNode'])

        completeTask(objB).then((response) => {
          if (response.code == 0) {
            this.go()
          }else{
            this.$message({"duration":'800',message:response.msg,type:'success',customClass:'zZindex'});

          }
        })
      })
    },
    /**
     * 完成AdHoc任务
     */
    completeAdHoc: function() {
      this.loading=false;
      new Promise((resolve, reject) => {
        const objB = JSON.parse(JSON.stringify(this.agreeAdHocSubProcess))
        delete (objB['usersIds'])
        delete (objB['userNames'])
        delete (objB['nextNode'])
        objB["formData"]=  this.task.formData
        objB["taskId"]=this.task.taskId
        this.loading=true
        completeAdHoc(objB).then((response) => {
          if (response.code == 0) {
            this.go()
          }else{
            this.$message({"duration":'800',message:response.msg,type:'success',customClass:'zZindex'});

          }
          this.loading=false
        })
      })
    },
    informedReset() {
      this.informed.informed = false
      this.existData = []
      this.informed.usersInfo = []
    },
    handleReset(name) {
      this.handlerModel = false
      this.informed.informed = false
      this.informed.opinion = ''
      this.informedReset()
      this.loading=false;
      if (name=='task'){
        this.task.opinion=""
        this.task.priority='50'
        this.task.taskTitle=JSON.parse(JSON.stringify(this.tmpTaskInfo)).taskTitle
      }
      if (name == 'transferTask') {
        this.handleTransferTaskReset()
      }
      if (name == 'addNode') {
        this.handleAddNodeReset()
      }
      if (name == 'transactionUrge') {
        this.handleTransactionUrgeReset()
      }
      if (name == 'addSign') {
        this.handleAddSignReset()
      }
      if (name == 'agreeAdHocSubProcess') {
        this.agreeAdHocSubProcess.show=false;
      }
      if (name == 'backToNode') {
        this.handleBackToNodeReset()
      }
      if (name == 'taskSequence') {
        this.handlerSequenceModel=false
      }
    },
    handleTransferTaskReset() {
      this.transferTask.usersInfo = {}
      this.singleUserData = {}
      this.transferTask.option = ''
      this.transferTask.model = false
    },
    handleBackToNodeReset() {
      this.backToNodeForm.usersInfo = {}
      this.backToNodeForm.show = false
      this.backToNodeForm.option = ''
      this.backToNodeForm.newActivityId = ''
      this.singleUserData = {}
    },
    handleTransactionUrgeReset() {
      this.transactionUrge.usersInfo = {}
      this.singleUserData = {}
      this.transactionUrge.newActivityId = ''
      this.transactionUrge.option = ''
      this.transactionUrge.show = false
    },
    handleAddNodeReset() {
      this.singleUserData = {}
      this.addNode.nextId = ''
      this.addNode.userTaskName = ''
      this.addNode.show = false
    },
    handleAddSignReset() {
      this.addSign.usersInfo = []
      this.addSign.userTaskName = ''
      this.addSign.nextId = ''
      this.addSign.doUserId = ''
      this.addSign.show = false
      this.existData = []
    },
    informedHandler() {
      this.informedTask()
    },
    transferTaskHandler() {
      this.transferTaskAction()
    },

    action: function(action,type) {
      if (typeof action === 'object') {
        this.alias = action.alias
      } else {
        this.alias = action
      }
      if (type){
        this.getFormData()
        this.alias="sequence";
        const obj = JSON.parse(JSON.stringify(this.nextNode))
        this.taskSequenceForm.taskTitle=this.task.taskTitle;

        var sequenceNode=[];
        obj.forEach((item,index,array)=>{
          //执行代码
          if (item.taskId==action.targetRef){
            sequenceNode.push(item);

          }
        })
        this.sequenceNode=sequenceNode;

        this.handlerSequenceModel=true;
      }else{
        switch (this.alias) {
          case 'agree':// 普通任务正常办理

            this.task.action = 'agree'
            this.task.actionName = 'agree'
            this.task.formType = 'inner'
            this.getFormData()
            this.handlerModel = true
            break
          case 'pass':// 多实例通过

            this.task.action = 'pass'
            this.task.actionName = 'pass'
            this.task.formType = 'inner'
            this.getFormData()
            this.handlerModel = true
            break
          case 'unPass':// 多实例不通过

            this.task.action = 'unPass'
            this.task.actionName = 'unPass'
            this.task.formType = 'inner'
            this.getFormData()
            this.handlerModel = true
            break
          case 'informed':
            this.informed.informed = true
            break
          case 'agreeAdHocSubProcess':
            this.getFormData()
            this.agreeAdHocSubProcess.show=true;
            break
          case 'transferTask':
            this.transferTask.model = true
            break
          case 'invalid':
            this.invalidTaskAction()
            break
          case 'headmap':
            this.headMapAction()
            break
          case 'flowImage':
            this.flowImageAction()
            break
          case 'approvalHistory':
            this.opinionAction()
            break
          case 'transactionUrge':

            this.transactionUrgeAction()
            break
          case 'addNode':
            this.addNodeAction()
            break
          case 'addSignNode':

            this.addSignNode()
            break
          case 'saveDraft':
            this.saveAction()
            break
          case 'backToNode':

            this.backToNodeAction()
            break
          case 'print':

            window.print()
            break
          default:

            this.task.action = 'agree'
            this.task.actionName = 'agree'
            this.task.formType = 'inner'
            this.getFormData()
            this.handlerModel = true
        }
      }


    },
    backToNodeAction: function() {
      getBackNode(this.taskId).then((response) => {
        if (response.code == 0) {
          this.backToNodeForm.nodeArray = response.data
        }
        this.backToNodeForm.show = true
      })
      this.backToNodeForm.taskTitle = this.task.taskTitle
      // getBackNode
    },
    saveAction: function() {
      var obj = {}
      obj['taskId'] = this.taskId
      const that = this
      this.getFormData()
      setTimeout(function() {
        var formData = that.task.formData
        obj['formData'] = formData
        saveform(obj).then((response) => {
          if (response.code == 0) {
            that.$message({"duration":'800',message:'保存成功',type:'success',customClass:'zZindex'});


          }
        })
      }, 300)
    },
    addNodeAction: function() {
      this.handleReset('addNode')
      getOutgoingFlows(this.taskId).then((response) => {
        if (response.code == 0) {
          this.transactionUrgeData.nodeArray = response.data
          this.transactionUrge.taskTitle = this.task.taskTitle
          this.addNode.show = true

        }
      })

    },
    addSignNode: function() {
      this.handleAddSignReset()
      getOutgoingFlows(this.taskId).then((response) => {
        if (response.code == 0) {
          this.transactionUrgeData.nodeArray = response.data
          this.transactionUrge.taskTitle = this.task.taskTitle
          this.addSign.show = true
        }
      })
    },
    transactionUrgeAction: function() {
      getTransactionUrge(this.taskId).then((response) => {
        if (response.code == 0) {
          this.transactionUrgeData.nodeArray = response.data
          this.transactionUrge.taskTitle = this.task.taskTitle
          this.transactionUrge.show = true
        }
      })
    },
    opinionAction: function() {
      this.opinion.show = true
      opinionTask(this.processInstanceId).then((response) => {
        if (response.code == 0) {
          this.opinion.tableData = response.data
        }
      })
    },
    headMapAction: function() {
      var url=this.headMap.base + this.processDefinitionId + '&t=' + new Date().getTime();
      this.headMap.src =url
      this.headMap.show = true
    },
    flowImageAction: function() {
      var url=this.flowImage.base + this.processInstanceId + '&t=' + new Date().getTime();
      this.flowImage.src = url;
      this.flowImage.show = true
    },
    invalidTaskAction: function() {
      invalidTask(this.taskId).then((response) => {
        if (response.code == 0) {
          this.$message({"duration":'800',message:'作废成功',type:'success',customClass:'zZindex'});

          const that = this
          setTimeout(function() {
            that.go()
          }, 300)
        }
      })
    },
    go: function() {
      this.handlerModel = false

      if (Boolean(this.monitor)) {
       //流程监控过来的
        this.$store.dispatch('tagsView/delView', this.$route)
        this.$router.push({name: 'cockpitTaskIndex', query: {t: new Date().getTime()}})
        return
      }
      // 调用全局挂载的方法
      if (this.fromIndex) {
        //首页过来的
        this.jsonData={}
        this.editData={}
        this.fromIndex=false;
        this.$emit('closeEvent', true)
      }else{

        this.$store.dispatch('tagsView/delView', this.$route)
        this.$router.push({name: 'myTask', query: {t: new Date().getTime()}})
      }

    },
    getNextNode: function() {
      getNextNode(this.taskId).then((response) => {
        if (response.code == 0) {
          this.nextNode = response.data
          this.task.nextNode = response.data
          this.existData=[];
          this.existData = this.task.nextNode
          this.agreeAdHocSubProcess.nextNode=response.data;
          var data=response.data;
          var nextNodeName=[];
          var nextNodeNameOptions=[];
          for (let i = 0; i <data.length ; i++) {
            var d=  data[i];
            nextNodeName.push(d.taskName)
            nextNodeNameOptions.push(d.taskName)

          }
          this.agreeAdHocSubProcess.nextNodeName=nextNodeName;
          this.agreeAdHocSubProcess.nextNodeNameOptions=nextNodeNameOptions;
          if (this.nextNode.length==0){
            this.nextNode.push({ "taskId": "",
              "taskName": "等待其他任务汇总",
              "nodeType": "userTask", });
          }

        }
      })
    },
    renderByTaskId: function(id) {
      try {
        renderByTaskId(id).then((response) => {
          if (response.code == 0) {
            if (response.data){
              this.jsonData = JSON.parse(response.data)
            }
            if (response.editData){
              this.editData = JSON.parse(response.editData)

            }
          } else {
            this.go()
          }
        })
      } catch (e) {

      }
    },
    getTaskBtn: function(id) {
      try {
        getTaskBtn(id).then((response) => {
          if (response.code == 0) {
            this.taskBtns = response.data
            this.multiInstanceTaskBtns = response.multiInstance
            this.taskSequence = response.sequence
            this.isSpinShow = false
            var taskTitle = response.taskTitle
            var processDefinitionId = response.processDefinitionId
            this.processDefinitionId = processDefinitionId
            var processInstanceId = response.processInstanceId
            this.processInstanceId = processInstanceId
            this.task.taskTitle = taskTitle
            this.tmpTaskInfo.taskTitle = taskTitle
            this.informed.taskTitle = taskTitle
            this.agreeAdHocSubProcess.taskTitle = taskTitle
          } else {
            this.go()
          }
        })
      } catch (e) {
        this.go()
      }
    }

  }

}

</script>
<style lang="scss">
  .task-card {
    margin-top: 10px;
  }

  .container {
    height: auto !important;
    min-height: 1650px;
  }
  .zZindex {
    z-index:3000 !important;
  }

</style>
